<template>
  <el-card class="box-card" v-loading="loading">
    <div slot="header" class="clearfix">
      <span>财务信息</span>
    </div>
    <div class="app-container">
      <el-form :inline="true" :model="form" ref="refForm" class="demo-form-inline">
        <el-form-item label="查询时间" prop="search_date">
          <el-date-picker
            v-model="form.time"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="yyyy-MM-dd"
            :picker-options="pickerDayStep">
          </el-date-picker>
        </el-form-item>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="submitFilter">搜索</el-button>
      </el-form>
    </div>
    <el-table border :data="[tableData]" class="el-table-align-center">
      <el-table-column label="充值次数" prop="rechargeNum"></el-table-column>
      <el-table-column label="充值金额" prop="rechargeSum">
        <template slot-scope="{row}">
          {{row.rechargeSum | currency}}
        </template>
      </el-table-column>
      <el-table-column label="取款次数" prop="withdrawNum"></el-table-column>
      <el-table-column label="取款总额">
        <template slot-scope="{row}">
          {{row.withdrawSum | currency}}
        </template>
      </el-table-column>
      <el-table-column label="红利">
        <template slot-scope="{row}">
          {{row.bonusSum | currency}}
        </template>
      </el-table-column>
    </el-table>
  </el-card>
</template>

<script>
import { getMemberFinance } from '@/services/api/member';
// import formFilter from './formFilter';
import { grid, pickerOption } from '@/build';

export default {
  name: 'user-finance',
  components: {
    // formFilter
  },
  mixins: [grid, pickerOption],
  data() {
    // let times = _.toPeriod({
    //  start: [-1, 'days'],
    //  end: [0, 'days'],
    //  format: 'YYYY-MM-DD'
    // });
    // 本月时间本月1号至当前时间
    const monthTime = [moment().startOf('month').format('YYYY-MM-DD'), moment().format('YYYY-MM-DD')];

    return {
      loading: false,
      colConfigs: [],
      tableData: {},
      form: {
        time: monthTime,
      },
      filters: {
        userId: this.$store.state.member.member_id,
        stime: moment(monthTime[0]).valueOf(),
        etime: moment(monthTime[1]).valueOf() + 86399999,
      },
    };
  },
  mounted() {
    this.bindGet(getMemberFinance, 'tableData', {
      action: 'getGrid',
      sendingData: 'filters',
    });

    this.getAll();
  },
  methods: {
    submitFilter() {
      const { time } = this.form;
      let stime;
      let etime;
      if (!_.isUndefined(time) && _.isArray(time)) {
        stime = moment(time[0]).valueOf();
        etime = moment(time[1]).valueOf() + 86399999;
      }

      this.filters = { ...this.filters, stime, etime };
      this.gridSearch();
    },
  },
};
</script>

<style lang="scss">

  .el-table-no-head {
    .el-table__header-wrapper {
      display: none;
    }
  }

</style>
